package com.zzuli.dcxt.controller;

import com.zzuli.dcxt.dao.CategoryMapper;
import com.zzuli.dcxt.entiy.Category;
import com.zzuli.dcxt.entiy.Dishes;
import com.zzuli.dcxt.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Controller
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @Autowired
    private CategoryMapper categoryMapper;

    @RequestMapping("/catelist")
    public String catelist(Model model){
        List list = categoryService.getCategoryList();
        model.addAttribute("list",list);
        return "typelist";
    }

    @RequestMapping("/addCategory")
    public String addCategory(Category category, HttpServletRequest request){
        categoryMapper.insert(category);
        List<Category> list = categoryService.getCategoryList();
        request.setAttribute("list",list);
        return "typelist";
    }

    @RequestMapping("/deleteCategory")
    public String deleteCategory(int id){
        categoryMapper.deleteByPrimaryKey(id);
        return "redirect:/catelist.do";
    }
}
